﻿#if ODIN_INSPECTOR
using Sirenix.OdinInspector;
#endif
using UnityEngine;

namespace JH
{
    /// <summary>
    ///  图表中任意继承自MaskableGraphic的组件的基类，主要用于编辑器下刷新渲染
    /// </summary>
    public abstract class BasicGraphicRender<TPoint> : BasicGraphic<TPoint>, IChartRender
        where TPoint : struct
    {
        /// <summary>
        ///  渲染优先级，数值越小，渲染越靠前
        /// </summary>
        [field: SerializeField]
#if ODIN_INSPECTOR
        [field:LabelText("渲染优先级")]
#endif
        public int Priority { get; set; }

        /// <summary>
        ///  渲染
        /// </summary>
        public void Render()
        {
            OnUpdateRender();

            // 设置脏数据标志
            SetVerticesDirty();
        }

        /// <summary>
        ///  更新渲染时的方法
        /// </summary>
        protected virtual void OnUpdateRender()
        {
        }

        /// <summary>
        ///  布局变化也要刷新渲染
        /// </summary>
        protected override void OnRectTransformDimensionsChange()
        {
            base.OnRectTransformDimensionsChange();
            SetVerticesDirty();
        }
    }
}